/*
 * @Author: czy
 * @Date: 2021-05-30 21:56:49
 * @LastEditTime: 2021-06-05 22:47:19
 */
#include "string.h"

#include "stdio.h"
#include "malloc.h"

int testmalloc(int argc, char *argv[])
{
    char *str;
    str = (char *)malloc(15);
    strcpy(str, "Hello world!");
    printf("\033[35mTest malloc:\n\033[0m");
    printf("Address: %p\nData: %s\n", str, str);
    free((long unsigned)str);
    printf("\n");

    str = (char *)kmalloc(15);
    strcpy(str, "Hello world!");
    printf("\033[35mTest kmalloc:\n\033[0m");
    printf("Address: %p\nData: %s\n", str, str);
    kfree((long unsigned)str);
    printf("\n");

    int *array;
    array = (int *)calloc(8, sizeof(int));
    printf("\033[35mTest calloc:\n\033[0m");
    printf("Address: %p\nData: \t", array);
    for (int i = 0; i < 8; i++)
    {
        array[i] = i * i;
    }
    for (int i = 0; i < 8; i++)
    {
        printf("%d\t", array[i]);
    }
    printf("\n\n");
    free((long unsigned)array);
    return 1;
}
